home *** CD-ROM | disk | FTP | other *** search
/ Interactive Web Graphics with Shout 3D / Interactive Web Graphics With Shout 3D.iso / mac / Shout3Ddemo / S3D_2E1.exe / Shout3d_runtime / codebase / custom_nodes / InvertPlusOverlayTextEffect.java < prev    next >
Text File  |  2000-09-21  |  3KB  |  88 lines

  1. /**    
  2.     Company:        Eyematic Interfaces
  3.     Project:        Shout3D Core
  4.     Class:            TestEffect
  5.     Date:            March 23, 2000
  6.     Description:    A simple example of a PostRenderEffect that inverts the colors of the scene and adds some text on top.
  7.     (C) Copyright Eyematic Interfaces, Inc. - 1997/1998/1999/2000 - All rights reserved
  8.  */
  9.  
  10. package custom_nodes;
  11. import shout3d.core.*;
  12. import shout3d.*;
  13. import shout3d.core.awt.*;
  14. import java.awt.*;
  15. import java.awt.image.*;
  16.  
  17. /**
  18.  * TestEffect
  19.  * 
  20.  * @author Dave Westwood
  21.  */
  22.  
  23. public class InvertPlusOverlayTextEffect extends PostRenderEffect{
  24.  
  25.     /**
  26.      * Constructs a default InvertPlusOverlayTextEffect node.
  27.      */
  28.     public InvertPlusOverlayTextEffect(){}
  29.  
  30.     int[] defaultStartPosition = { 160, 0 };
  31.     int[] defaultTextVelocity  = { 0,   10 };
  32.     
  33.     final public    BooleanField    invertEnabled    = new BooleanField(this, "invertEnabled",  Field.ANY, true);
  34.     final public    StringField        overlayText        = new StringField(this, "overlayText",  Field.ANY, "WAZZUP!");
  35.     final public    IntArrayField    startPosition    = new IntArrayField(this, "startPosition",  Field.ANY, defaultStartPosition);
  36.     final public    IntArrayField    textVelocity    = new IntArrayField(this, "textVelocity",  Field.ANY, defaultTextVelocity);
  37.  
  38.     Font bigFont = new Font("Arial", Font.BOLD, 30);
  39.     int x, y = 0;
  40.     int xVelo = 0;
  41.     int yVelo = 10;
  42.     boolean firstTime = true;
  43.     
  44.     public void filter(Graphics g, int surface_pixel_bits[], float z_buffer[], int deviceWidth, int deviceHeight){
  45.         if (surface_pixel_bits == null)
  46.             return;
  47.  
  48.         // Invert
  49.         if (invertEnabled.getValue()){
  50.             for (int i=0;i<surface_pixel_bits.length;i++){
  51.                 surface_pixel_bits[i] = 0xff000000 + 
  52.                                         ((255-((surface_pixel_bits[i]>>16)&0xff))<<16) +    // invert red
  53.                                         ((255-((surface_pixel_bits[i]>>8)&0xff))<<8) +      // invert green
  54.                                         ((255-((surface_pixel_bits[i])&0xff)));             // invert blue
  55.             }
  56.         }
  57.  
  58.         // initialize position and velocity
  59.         if (firstTime && startPosition.getValue() != null && startPosition.getValue().length > 1){
  60.             x = startPosition.getValue()[0];
  61.             y = startPosition.getValue()[1];
  62.         }
  63.         if (firstTime && textVelocity.getValue() != null && textVelocity.getValue().length > 1){
  64.             xVelo = textVelocity.getValue()[0];
  65.             yVelo = textVelocity.getValue()[1];
  66.         }
  67.         firstTime = false;
  68.         
  69.         // Draw some text
  70.         g.setFont(bigFont);
  71.         g.setColor(java.awt.Color.green);
  72.         if (x > deviceWidth)
  73.             x = 0;
  74.         else if (x < 0)
  75.             x = deviceWidth;
  76.         else 
  77.             x+= xVelo;
  78.         
  79.         if (y > deviceHeight)
  80.             y = 0;
  81.         else if (y < 0)
  82.             y = deviceHeight;
  83.         else
  84.             y+= yVelo;
  85.         g.drawString(overlayText.getValue(), x, y);
  86.         
  87.     }
  88. }